﻿$(function () {

    var curLeft = 0;
    var widthCount = ($("#photo_wrap li").size() - 9) * 74;
    var $photo_wrap_ul = $("#photo_wrap ul");
    var $arr_left = $("#arr_left");
    var $arr_right = $("#arr_right");
    if ($("#photo_wrap li").size() <= 10)
        $arr_right.addClass("arr_right_none");

    //左箭头
    $arr_left.click(function () {
        curLeft = Math.abs(parseInt($photo_wrap_ul.css("margin-left")));
        if (curLeft != 0 && !$photo_wrap_ul.is(":animated")) {
            $photo_wrap_ul.animate({ "margin-left": "+=296px" }, 300, function () {
                curLeft = Math.abs(parseInt($photo_wrap_ul.css("margin-left")));
                if (curLeft == 0)
                    $arr_left.addClass("arr_left_none");
            });
            $arr_right.removeClass("arr_right_none");
        }
    });

    //右箭头
    $arr_right.click(function () {
        curLeft = Math.abs(parseInt($photo_wrap_ul.css("margin-left")));
        if (curLeft <= widthCount && !$photo_wrap_ul.is(":animated")) {
            $photo_wrap_ul.animate({ "margin-left": "-=296px" }, 300, function () {
                curLeft = Math.abs(parseInt($photo_wrap_ul.css("margin-left")));
                if (curLeft > widthCount)
                    $arr_right.addClass("arr_right_none");
            });
            $arr_left.removeClass("arr_left_none");
        }
    });

    //单击缩略图
    $("#photo_wrap a[id!=photo_back]").click(function () {
        $(this).addClass("current").parent().siblings().find("a").removeClass("current");
        $("#AloneMin").show();
        $("#photo_alone .content img").hide().attr("src", $(this).attr("name"));
        $("#photo_alone .filedes").html($(this).attr("des"));
        //图片滚动
        var clickID = $(this).parent().index();
        curLeft = Math.abs(parseInt($("#photo_wrap ul").css("margin-left")));
        if (curLeft != 0 || clickID >= 8) {	//判断第一屏
            if (clickID % 4 == 0) {						//判断是否是边缘图片
                if (curLeft > (clickID - 4) * 74)//左移
                    $arr_left.click();
                if (curLeft < (clickID - 4) * 74)//右移
                    $arr_right.click();
            }
        }

        var ParentId = $(this).attr("id").replace("photo", "");
        var ParentType = $("#ParentType").val();
        var dataString = "ParentId=" + ParentId;
        dataString += "&ParentType=" + ParentType;
        //更新当前ID
        $("#ParentId").val(ParentId);
        //异步获取评论信息
        $.ajax({ type: "post", url: "Ajax/GetReview.ashx", data: dataString, success: function (result) {
            $("#review_list").html(result);
        }
        });
    });

    //返回第一张
    $("#photo_back").click(function () {
        $photo_wrap_ul.animate({ "margin-left": "0" }, 500);
        $("#photo_wrap a:first").click();
        $arr_left.addClass("arr_left_none");
        if ($("#photo_wrap li").size() > 10)
            $arr_right.removeClass("arr_right_none");
    });

    //鼠标大图移动
    $("#photo_alone .content img").mousemove(function (e) {
        var curIndex = $("#photo_wrap a.current").parent().index();
        var positionX = e.originalEvent.x - $(this).offset().left || e.originalEvent.layerX - $(this).offset().left || 0;

        if (positionX <= $(this).width() / 2) {
            if (curIndex != 0) {
                $(this).css({ "cursor": "url(images/mouse_left.cur),auto" });
                //$(this).attr("alt","单击跳到上一张");
            } else {
                $(this).css({ "cursor": "auto" });
                //$(this).attr("alt","已是第一张");
            }
        } else {
            $(this).css({ "cursor": "url(images/mouse_right.cur),auto" });
            //$(this).attr("alt","单击跳到下一张");
        }
    });

    //鼠标大图单击
    $("#photo_alone .content img").click(function (e) {
        var positionX = e.originalEvent.x - $(this).offset().left || e.originalEvent.layerX - $(this).offset().left || 0;
        if (positionX <= $(this).width() / 2)
            $("#photo_wrap a.current").parent().prev().find("a").click();
        else
            $("#photo_wrap a.current").parent().next().find("a").click();
    });

});